package com.iwhalecloud.bss.kite.cucc.service.route.impl;

import java.util.Map;
import java.util.Objects;

import org.springframework.stereotype.Component;

import com.iwhalecloud.bss.kite.common.chain.HandlerExecutionChain;
import com.iwhalecloud.bss.kite.cucc.client.dto.inf.InfServContextDTO;
import com.iwhalecloud.bss.kite.cucc.service.route.InfServReqParam;
import com.iwhalecloud.bss.kite.cucc.service.route.match.impl.GoodsCategroyMatchHandler;
import com.iwhalecloud.bss.kite.cucc.service.route.strategy.IInfServStrategy;

@Component
public class SceneCommitInfServRoute extends AbstractInfServRoute {

    /**
     * Description: <br>
     * 订单提交
     * 
     * @author XXZ<br>
     * @taskId <br>
     * @param context
     * @return <br>
     */
    @Override
    public Map<String, Object> commitScene(InfServContextDTO context) {
        InfServReqParam param = new InfServReqParam();
        param.setContext(context);

        // 1.计算调用接口策略
        IInfServStrategy infServStrategy = getInfServStrategy(param);

        // 2.执行接口服务调用策略(调用订单归集接口)
        return infServStrategy.orderCenterPathVariable(context);
    }

    /**
     * 更新工单信息
     * 
     * @return <br>
     */
    public Map<String, Object> updateWordOrder(InfServContextDTO context) {
        InfServReqParam param = new InfServReqParam();
        param.setContext(context);

        // 1.计算调用接口策略
        IInfServStrategy infServStrategy = getInfServStrategy(param);

        // 2.执行接口服务调用策略(调用订单更新接口)
        return infServStrategy.orderCenterUpdatePiece(context);
    }

    @Override
    public void registerStrategyMatchHandler(HandlerExecutionChain<InfServReqParam> chain) {
        if (Objects.nonNull(chain)) {
            // 商品分类匹配
            chain.addHandler(new GoodsCategroyMatchHandler());
        }
    }

}
